<?php

use console\db\channels\TransferTableMigration;
use yii\db\Query;

/**
 * 球迷学院分享迁移
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m300060_000006_t_college_share extends TransferTableMigration {

    /**
     * @inheritdoc
     */
    public $sourceDb = 'olddb';

    /**
     * @inheritdoc
     */
    public function validateTransfer(&$data) {
        if (!parent::validateTransfer($data)) {
            return false;
        }
        $data['img'] = str_replace('http://img.lnts.cn', '/uploads', $data['img']);
        $data['link'] = str_replace('http://img.lnts.cn', '/uploads', $data['img']);
        return true;
    }

    /**
     * @inheritdoc
     */
    public function getTransferOptions() {
        return [
            'table' => [
                'college_share' => 'a_share',
            ],
            'columns' => [
                'id',
                'name',
                'description' => 'describe',
                'icon' => 'img',
                'cover' => 'link',
                'status' => function($data) {
                    if ($data['status']) {
                        return 10;
                    }
                    return 0;
                },
                'created_at' => function() {
                    return strtotime('-1 year');
                },
                'updated_at' => function() {
                    return time();
                },
            ],
        ];
    }

}
